package cn.doitedu.smart_marketing.functions;

import cn.doitedu.datagen.LogBean;
import cn.doitedu.smart_marketing.beans.RuleMatchResult;
import cn.doitedu.smart_marketing.rule.RuleMatcher;
import cn.doitedu.smart_marketing.rule.TestRule;
import org.apache.flink.streaming.api.functions.KeyedProcessFunction;
import org.apache.flink.util.Collector;

/***
 * @author hunter.d
 * @qq 657270652
 * @wx haitao-duan
 * @date 2021/7/22
 **/
public class RuleProcessor extends KeyedProcessFunction<String, LogBean, RuleMatchResult> {

    @Override
    public void processElement(LogBean value, Context ctx, Collector<RuleMatchResult> out) throws Exception {
        RuleMatcher ruleMatcher = new RuleMatcher();
        RuleMatchResult ruleMatchResult = ruleMatcher.matchRule(value);
        if(ruleMatchResult != null) {
            out.collect(ruleMatchResult);
        }
    }
}
